//$URL: http://dasding.googlecode.com/svn/branches/testzeugs/data/data/src/main/java/de/piratech/dasding/data/AbstractDataObject.java $
//$Id: AbstractDataObject.java 90 2012-11-20 18:42:49Z amuthmann@gmail.com $
/*
 * Copyright 2012 deveth0.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.piratech.dasding.data;

import de.piratech.dasding.data.database.DataType;
import javax.xml.bind.annotation.XmlID;
import net.vz.mongodb.jackson.ObjectId;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;

/**
 * An abstract data object which defines an id
 *
 * @author deveth0
 */
public abstract class AbstractDataObject {

  @JsonProperty("_id")
  @ObjectId
  private String mId;
  @JsonProperty("_rev")
  private String mRev;
  private DataType mDatatype;

  @XmlID
  @ObjectId
  public String getId() {
    return mId;
  }

  public void setId(String pId) {
    this.mId = pId;
  }

  @JsonProperty("_rev")
  public String getRevision() {
    return this.mRev;
  }

  @JsonProperty("_rev")
  public void setRevision(String pRev) {
    this.mRev = pRev;
  }

  public DataType getDataType() {
    return mDatatype;
  }

  public void setDataType(DataType pType) {
    this.mDatatype = pType;
  }

  @JsonIgnore
  public abstract boolean isValid();

  @Override
  public int hashCode() {
    int hash = 5;
    hash = 67 * hash + (this.mId != null ? this.mId.hashCode() : 0);
    return hash;
  }

  @Override
  public boolean equals(Object pObj) {
    if (pObj == null) {
      return false;
    }
    if (getClass() != pObj.getClass()) {
      return false;
    }
    final AbstractDataObject other = (AbstractDataObject) pObj;
    if ((this.mId == null) ? (other.mId != null) : !this.mId.equals(other.mId)) {
      return false;
    }
    return true;
  }
}
